home *** CD-ROM | disk | FTP | other *** search
/ Aminet 51 / Aminet 51 (2002)(GTI - Schatztruhe)[!][Oct 2002].iso / Aminet / dev / misc / FlexCat.lha / Lib / C++_CatalogF.cc < prev    next >
Encoding:
C/C++ Source or Header  |  1999-11-28  |  3.3 KB  |  104 lines

  1. ##rem $Id: C++_CatalogF.cc,v 1.2 1999/11/28 03:36:41 carlos Exp $
  2.  
  3. //   Multipurpose CatalogF class implementation
  4. //   Written by Antonio J. Gomez Glez. on 20.6.94
  5. //   You MUST include CatalogF.h in your code. 
  6. //   If you use FlexCat, you only have to include the file generated
  7. //   with it.
  8.  
  9. #include "CatalogF.h"
  10.  
  11. extern "C" {
  12. #include <clib/locale_protos.h>
  13. #include <inline/locale.h>
  14. #include <clib/exec_protos.h>
  15. };
  16.  
  17. unsigned CatalogF::counter = 0;     // counter of open catalogs
  18. struct LocaleBase* LocaleBase = 0;  // We will try to open locale.library
  19.  
  20. // Constructor:
  21. // Needs:- filename of the catalog to be used. NEEDED!!
  22. //       - built in language of the catalog descriptor. defaults to "english"
  23. //       - language requested. Otherwise, it will use the user defined one.
  24. //       - requested version number for the catalog. defaults to any.
  25. //       - Locale (as returned by OpenLocale). defaults to user defined one.
  26. //
  27. // Try to open locale.library for the first CatalogF object declared. And
  28. // keeps with this with following objects.
  29. // Counts the number of defined objects.
  30. // And opens the catalog if avaible.
  31.  
  32. CatalogF::CatalogF( const STRPTR   catalogFileName,
  33.                     const STRPTR   builtInLanguage,
  34.                     const LONG     versionNumber,
  35.                     const STRPTR   languageName,
  36.                     struct Locale* loc )
  37. {
  38.   if ( counter == 0 )  // means that this is the first object
  39.   {
  40.      LocaleBase = (struct LocaleBase* )OpenLibrary("locale.library", 38L );
  41.   }
  42.   counter++;
  43.  
  44.   if ( LocaleBase != 0 )  
  45.   {                  // locale.library is avaible
  46.     LONG tag = TAG_IGNORE;  // in case language not provided use default
  47.     
  48.     if (languageName != 0)      // if language specified, use that
  49.     { 
  50.       tag = OC_Language;
  51.     }
  52.     thecatalog = OpenCatalog( loc,
  53.                               catalogFileName,
  54.                               OC_BuiltInLanguage, builtInLanguage,
  55.                               tag, languageName,
  56.                               OC_Version, versionNumber,
  57.                               TAG_DONE );
  58.   } // else use built-in strings                       
  59. }
  60.  
  61. // Destructor:
  62. // If locale.library was opened, try to close the catalog, even if no catalog
  63. // was opened (this is supported by CloseCatalog()).
  64. // When the counter of avaible objects reaches 0, it try to close locale.library
  65.  
  66. CatalogF::~CatalogF()
  67. {
  68.   counter--;
  69.   if ( LocaleBase != 0 )
  70.   { 
  71.     CloseCatalog( thecatalog );
  72.     if ( counter == 0 )
  73.     {
  74.       struct LocaleBase* lb = LocaleBase;
  75.       CloseLibrary( (struct Library* )lb );
  76.       LocaleBase = 0;
  77.     }
  78.   }
  79. }
  80.  
  81. // Retrive the string.
  82. // If there is locale.library and a opened catalog returns the catalog
  83. // string, else returns the built-in string.
  84. //
  85. // Needs a struct of type catMessage that contains the value ID and the
  86. // string itself. The name of this constant struct is the ID name. This way
  87. // we avoid the use of #define's or const, or any type of search ...
  88. // it returns a const pointer (STRPTR) to the string.
  89. // This method is constant so CatalogFs object can be declared to be const
  90.  
  91. const STRPTR
  92. CatalogF::GetStr(const CatMessage& mess) const
  93. {
  94.   if ( LocaleBase == 0 )
  95.   {
  96.      return( mess.textstring );
  97.   }
  98.   else
  99.   {
  100.      return( GetCatalogStr(thecatalog, mess.ID, mess.textstring) );
  101.   }
  102. }
  103.  
  104.